<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>练习</title>
</head>
<body>
<input type="text" id="d1">
<input type="button" value="添加帅哥" onclick="f1(2)">
<input type="button" value="添加美女" onclick="f1(1)">


<script>
function f1(x) {
  let i = document.querySelector("#d1");
 /* if(isNaN(i.value)) {
    console.log("输入有误");
  }*/
  let j = 0;
  let img = x==1 ? "../b.png" : "../a.jpeg"
  while (true) {
    let s = document.createElement("img");
    s.src = img;
    document.body.append(s);
    j++;
    if(j == i.value) {
      break;
    }
  }
}

</script>
</body>
</html>